//
//  BQAssistController.m
//  BeeQuick
//
//  Created by GuoDeJin on 2016/11/21.
//  Copyright © 2016年 six_group. All rights reserved.
//

#import "BQAssistController.h"
#import "AXFFeedbackController.h"
#import "AXFQuestionController.h"
#import "BQQingQingVc.h"
static NSString * cellID = @"cellID";
@interface BQAssistController ()

@end

@implementation BQAssistController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //初始化tableView为分组样式
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    
    //注册
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellID"];
    
    
    //cell的行高
    self.tableView.rowHeight = 60;
    
    //自定义导航条返回按钮
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"v2_goback"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonOF:)];
     self.navigationItem.leftBarButtonItem = barButtonItem;
}

//pop回去
- (void)buttonOF:(UIBarButtonItem *)batBtn{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

//视图将要被移除   显示tabbar
- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    self.tabBarController.tabBar.hidden = NO;
    
}
//视图将要显示  隐藏tabbar
- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    self.tabBarController.tabBar.hidden = YES;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    if (section == 1) {
        return 3;
    }
    return 1;
}
//cell间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID" forIndexPath:indexPath];
    

    //设置cell最顶端的间距
    self.tableView.contentInset = UIEdgeInsetsMake(80, 0, 0, 0);
    
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        
        //头像
        UIImageView *touXiangImage = [[UIImageView alloc]init];
        touXiangImage.image = [UIImage imageNamed:@"feedback_online"];
        [cell addSubview:touXiangImage];
        
        //namelabel
        UILabel *nameLabel = [[UILabel alloc]init];
        nameLabel.text = @"客服妹妹";
        nameLabel.font = [UIFont systemFontOfSize:14];
        [cell addSubview:nameLabel];
        
        //fuBiaoTiLabel
        UILabel *fuBiaoTiLabel = [[UILabel alloc]init];
        fuBiaoTiLabel.text = @"9点-24点实时回复";
        fuBiaoTiLabel.font = [UIFont systemFontOfSize:12];
        fuBiaoTiLabel.textColor = [UIColor lightGrayColor];
        [cell addSubview:fuBiaoTiLabel];
        
        //右边箭头
        UIButton *rightBtn = [[UIButton alloc]init];
        [rightBtn setImage:[UIImage imageNamed:@"baidu_wallet_arrow_right"] forState:UIControlStateNormal];
        [cell addSubview:rightBtn];
        
        //头像  约束
        [touXiangImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(cell.mas_centerY);
            make.left.mas_equalTo(10);
            make.width.mas_equalTo(50);
            make.height.mas_equalTo(40);
        }];
        //namelabel  约束
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(12);
            make.left.equalTo(touXiangImage.mas_right).offset(10);
        }];
        //fuBiaoTiLabel 约束
        [fuBiaoTiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(nameLabel.mas_bottom).offset(5);
            make.left.equalTo(nameLabel);
            
        }];
        //右边箭头按钮约束
        [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(cell.mas_centerY);
            make.right.mas_equalTo(-10);
        }];
        
    }else if(indexPath.section == 1 && indexPath.row == 0){
        
        //头像
        UIImageView *touXiangImage = [[UIImageView alloc]init];
        touXiangImage.image = [UIImage imageNamed:@"feedback_opinion"];
        [cell addSubview:touXiangImage];
        
        //namelabel
        UILabel *nameLabel = [[UILabel alloc]init];
        nameLabel.text = @"意见反馈";
        nameLabel.font = [UIFont systemFontOfSize:14];
        [cell addSubview:nameLabel];
        
        //fuBiaoTiLabel
        UILabel *fuBiaoTiLabel = [[UILabel alloc]init];
        fuBiaoTiLabel.text = @"1-2个工作日内反馈";
        fuBiaoTiLabel.font = [UIFont systemFontOfSize:12];
        fuBiaoTiLabel.textColor = [UIColor lightGrayColor];
        [cell addSubview:fuBiaoTiLabel];
        
        //右边箭头
        UIButton *rightBtn = [[UIButton alloc]init];
        [rightBtn setImage:[UIImage imageNamed:@"baidu_wallet_arrow_right"] forState:UIControlStateNormal];
        [cell addSubview:rightBtn];

        
        //头像  约束
        [touXiangImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(cell.mas_centerY);
            make.left.mas_equalTo(10);
            make.width.mas_equalTo(30);
            make.height.mas_equalTo(30);
        }];
        //namelabel  约束
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(12);
            make.left.equalTo(touXiangImage.mas_right).offset(10);
        }];
        //fuBiaoTiLabel 约束
        [fuBiaoTiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(nameLabel.mas_bottom).offset(5);
            make.left.equalTo(nameLabel);
            
        }];
        
        //右边箭头按钮约束
        [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(cell.mas_centerY);
            make.right.mas_equalTo(-10);
        }];

        
        
    }else if (indexPath.section == 1 && indexPath.row == 1){
        //头像
        UIImageView *touXiangImage = [[UIImageView alloc]init];
        touXiangImage.image = [UIImage imageNamed:@"feedback_question"];
        [cell addSubview:touXiangImage];
        
        //namelabel
        UILabel *nameLabel = [[UILabel alloc]init];
        nameLabel.text = @"常见问题";
        nameLabel.font = [UIFont systemFontOfSize:14];
        [cell addSubview:nameLabel];
        
        //fuBiaoTiLabel
        UILabel *fuBiaoTiLabel = [[UILabel alloc]init];
        fuBiaoTiLabel.text = @"配送时间、优惠券和退款流程等";
        fuBiaoTiLabel.font = [UIFont systemFontOfSize:12];
        fuBiaoTiLabel.textColor = [UIColor lightGrayColor];
        [cell addSubview:fuBiaoTiLabel];
        
        //右边箭头
        UIButton *rightBtn = [[UIButton alloc]init];
        [rightBtn setImage:[UIImage imageNamed:@"baidu_wallet_arrow_right"] forState:UIControlStateNormal];
        [cell addSubview:rightBtn];

        
        //头像  约束
        [touXiangImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(cell.mas_centerY);
            make.left.mas_equalTo(10);
            make.width.mas_equalTo(30);
            make.height.mas_equalTo(30);
        }];
        //namelabel  约束
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(12);
            make.left.equalTo(touXiangImage.mas_right).offset(10);
        }];
        //fuBiaoTiLabel 约束
        [fuBiaoTiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(nameLabel.mas_bottom).offset(5);
            make.left.equalTo(nameLabel);
            
        }];
        
        //右边箭头按钮约束
        [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(cell.mas_centerY);
            make.right.mas_equalTo(-10);
        }];

    }else{
        
        //头像
        UIImageView *touXiangImage = [[UIImageView alloc]init];
        touXiangImage.image = [UIImage imageNamed:@"feedback_telephone"];
        [cell addSubview:touXiangImage];
        
        //namelabel
        UILabel *nameLabel = [[UILabel alloc]init];
        nameLabel.text = @"客服电话";
        nameLabel.font = [UIFont systemFontOfSize:14];
        [cell addSubview:nameLabel];
        
        //fuBiaoTiLabel
        UIButton *fuBiaobtn = [[UIButton alloc]init];
        [fuBiaobtn setTitle:@"400-8484-842" forState:UIControlStateNormal];
        [fuBiaobtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        fuBiaobtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [cell addSubview:fuBiaobtn];
        
        //头像  约束
        [touXiangImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(cell.mas_centerY);
            make.left.mas_equalTo(10);
            make.width.mas_equalTo(30);
            make.height.mas_equalTo(30);
        }];
        //namelabel  约束
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(12);
            make.left.equalTo(touXiangImage.mas_right).offset(10);
        }];
        //fuBiaoTiLabel 约束
        [fuBiaobtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(nameLabel.mas_bottom).offset(5);
            make.left.equalTo(nameLabel);
            make.height.mas_equalTo(20);
//            make.width.mas_equalTo(200);
        }];
        
        
        [fuBiaobtn addTarget:self action:@selector(dianHua) forControlEvents:UIControlEventTouchUpInside];
        
    }

    
    return cell;
}

#pragma mark - cell点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //取消cell的选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if (indexPath.section == 0 && indexPath.row == 0) {
        
        [self pushQingQing];
        
    }else if (indexPath.section == 1 && indexPath.row == 0) {
        
        [self feedback];
        
    }
    else if(indexPath.section == 1 && indexPath.row == 1) {
        
        [self question];
        
    }
    else if (indexPath.section == 1 && indexPath.row == 2) {
        
        [self tanChuang];
    }
}


-(void)pushQingQing{
    
    
    BQQingQingVc *qingQingView = [[BQQingQingVc alloc]init];
    
    
    [self.navigationController pushViewController:qingQingView animated:YES];

    
    
}



- (void)feedback
{
    
    AXFFeedbackController *feedbackVC = [[AXFFeedbackController alloc]init];
    
    [self.navigationController pushViewController:feedbackVC animated:YES];
    
}

- (void)question
{
    //跳转
    AXFQuestionController *questionVc = [[AXFQuestionController alloc]init];
    
    [self.navigationController pushViewController:questionVc animated:YES];
}

//电话btn点击事件
- (void)dianHua{
    
    [self tanChuang];
    
}
//打电话方法
- (void)phone{
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://400-8484-842"]];
}
//弹窗
- (void)tanChuang{
    
    //初始化AlertController
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"400-8484-842" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    
    
    //添加按钮
    [alertController addAction:[UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
        [self phone];
        
    }]];
    
    
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        //取消
        
    }]];
    
    //模态切换显示表单
    [self presentViewController:alertController animated:YES completion:nil];
    
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
